package com.sskj.phoenixcoin.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.phoenixcoin.activity.APpRechargeActivity;
import com.sskj.phoenixcoin.bean.AppBank;
import com.sskj.phoenixcoin.bean.AppBanlance;
import com.sskj.phoenixcoin.bean.AppImgBean;
import com.sskj.phoenixcoin.http.HttpConfig;

import java.io.File;


public class APpRechargeActivityPresenter extends BasePresenter<APpRechargeActivity> {
    // 充值
    public void recharge(String coinNum, String fee, String stockUserId, String coinType, String chargeType, String chargeImgUrl) {
        OkGo.<HttpData<Object>>post(HttpConfig.BASE_URL + HttpConfig.RECHARGE)
                .params("systemType", "ANDROID")
                .params("stockUserId", stockUserId)
                .params("coinType", coinType)
                .params("chargeType", chargeType)
                .params("coinNum", coinNum)
                .params("fee", fee)
                .params("chargeImgUrl", chargeImgUrl)
                .tag(this)
                .execute(new JsonCallBack<HttpData<Object>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<Object>> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.getMsg());
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.successUi();
                        }
                    }
                });
    }

    // 上传图片
    public void submitVerify(File file) {
        OkGo.<HttpData<String>>post("http://110754.com" + HttpConfig.IMGUPLOAD)
//        OkGo.<HttpData<String>>post(HttpConfig.BASE_URL + HttpConfig.IMGUPLOAD)
                .isMultipart(false)
                .params("file", file)
                .execute(new JsonCallBack<HttpData<String>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<String>> response) {
                        HttpData body = response.body();
                        if (body.status == HttpConfig.OK) {
                            String url = (String) body.getData();
                            mView.upload(true, url);
                        } else {
                            mView.upload(false, "");
                            ToastUtil.showShort(body.msg);
                        }
                    }
                });
    }

    // 获取官方银行账号
    public void getOfficialBank() {
        OkGo.<HttpData<AppBank>>post(HttpConfig.BASE_URL + HttpConfig.OFFICIALBANK)
                .params("systemType", "ANDROID")
                .tag(this)
                .execute(new JsonCallBack<HttpData<AppBank>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<AppBank>> response) {
                        HttpData body = response.body();
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.successBank((AppBank) body.getData());
                        } else {
                            ToastUtil.showShort(body.getMsg());
                        }
                    }
                });
    }
}
